package com.infolab.aims.domain.workorder;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import com.infolab.aims.GlobalConstant;
import com.infolab.aims.common.bean.AbstractModelBean;
import com.infolab.aims.domain.SystemUser;

@Entity
@Table(name="AMTB_WORKORDER_TECHNICIAN")
public class WorkOrderTechnician extends AbstractModelBean{
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private Integer workOrderTechnicianId;
	
	@ManyToOne
	@JoinColumn(name="workOderId")
	private WorkOrder workOrder;
	
	@ManyToOne
	@JoinColumn(name="technicianUserName",referencedColumnName="userName")
	private SystemUser technician;
	
	private Date timeStart;
	private Date timeEnd;
	
	@Transient
	private String startTm;
	
	@Transient
	private String endTm;
	
	
	
	@Transient
	private boolean woTimeUpdate;

	
	
	public String getStartTm() {
		return startTm;
	}
	public void setStartTm(String startTm) {
		this.startTm = startTm;
	}
	public String getEndTm() {
		return endTm;
	}
	public void setEndTm(String endTm) {
		this.endTm = endTm;
	}
	public boolean isWoTimeUpdate() {
		return woTimeUpdate;
	}
	public void setWoTimeUpdate(boolean woTimeUpdate) {
		this.woTimeUpdate = woTimeUpdate;
	}
	public Integer getWorkOrderTechnicianId() {
		return workOrderTechnicianId;
	}
	public void setWorkOrderTechnicianId(Integer workOrderTechnicianId) {
		this.workOrderTechnicianId = workOrderTechnicianId;
	}
	public WorkOrder getWorkOrder() {
		return workOrder;
	}
	public void setWorkOrder(WorkOrder workOrder) {
		this.workOrder = workOrder;
	}
	public SystemUser getTechnician() {
		return technician;
	}
	public void setTechnician(SystemUser technician) {
		this.technician = technician;
	}
	public Date getTimeStart() {
		return timeStart;
	}
	public void setTimeStart(Date timeStart) {
		this.timeStart = timeStart;
	}
	public Date getTimeEnd() {
		return timeEnd;
	}
	public void setTimeEnd(Date timeEnd) {
		this.timeEnd = timeEnd;
	}
	
	public String getTimeDisplay()
	{
		DateTimeFormatter fmt = DateTimeFormat.forPattern(GlobalConstant.DATE_TIME_FORMAT_JAVA);
		
		if(timeEnd!=null) return new DateTime(timeEnd.getTime()).toString(fmt);
		
		else if(timeStart!=null) return new DateTime(timeStart.getTime()).toString(fmt);
		
		return "";
			
	}
	
}
